package org.budo.dubbo.protocol.http.exporter.util;

import com.alibaba.dubbo.config.ApplicationConfig;
import com.alibaba.dubbo.config.ProtocolConfig;
import com.alibaba.dubbo.config.RegistryConfig;
import com.alibaba.dubbo.config.ServiceConfig;

/**
 * @author lmw
 */
public class ExportUtil {
    private static final String PROTOCOL_BUDO_HTTP = "budo-http";

    private static ApplicationConfig applicationConfig = new ApplicationConfig(ExportUtil.class.getName());

    private static RegistryConfig registryConfig = new RegistryConfig(RegistryConfig.NO_AVAILABLE);

    private static ProtocolConfig protocolConfig = new ProtocolConfig(PROTOCOL_BUDO_HTTP);

    public static ServiceConfig<Object> newServiceConfig(String interfaceType, Object beanRef) {
        ServiceConfig<Object> serviceConfig = new ServiceConfig<Object>(); // 此实例很重，封装了与注册中心的连接，请自行缓存，否则可能造成内存和连接泄漏
        serviceConfig.setApplication(applicationConfig);
        serviceConfig.setProtocol(protocolConfig);
        serviceConfig.setRegistry(registryConfig);

        serviceConfig.setInterface(interfaceType);
        serviceConfig.setRef(beanRef);
        return serviceConfig;
    }
}